using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;

namespace My.IdlConverter.Core.Types
{
    public class ReturnTypeFormatStrategy : ITypeFormatStrategy
    {
        public virtual string Format(IType type)
        {
            if (type == null)
                throw new ArgumentNullException("The type should no be null.");

            string prefix = type.Const ? "const " : "";
            string suffix = type.Ref ? "*" : "";
            StringBuilder sb = new StringBuilder();

            TypeMap map = type.Substitution;
            Debug.Assert(map.SubstitutionTypes.Count == 1);
            foreach (TypeMap.TypeSubstitution nextSubstitution in map.SubstitutionTypes)
            {
                string literal = nextSubstitution.Literal;
                sb.Append(prefix + literal + suffix);
            }

            return sb.ToString();
        }
    }
}
